package com.order.api.vo.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@ApiModel(value = "菜单详情返回")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MenuListResponse {

    @ApiModelProperty(value="菜单ID")
    private Long id;

    @ApiModelProperty(value="菜单名称")
    private String menuName;

    @ApiModelProperty(value="序号")
    private Integer orderNo;

    @ApiModelProperty(value="父ID")
    private Long parentId;

    @ApiModelProperty(value="菜单地址")
    private String url;

    @ApiModelProperty(value="状态,1:启用,0:禁用")
    private Integer status;

    @ApiModelProperty(value="子菜单集合")
    private List<MenuListResponse> childrens;

    public static List<MenuListResponse> buildTree(List<MenuListResponse> deptList, Long pid){
        List<MenuListResponse> treeList = new ArrayList<>();
        for (MenuListResponse dept : deptList) {
            if (dept.getParentId().equals(pid)){
                dept.setChildrens(buildTree(deptList, dept.getId()));
                treeList.add(dept);
            }
        }
        return treeList;
    }

}
